from .base import Base
from .Station import Station
from sqlalchemy.types import Integer
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.orm import relation
from sqlalchemy.databases import mysql

__all__ = ["Stop"]

class Stop(Base):

    __tablename__ = "stops"

    id = Column(Integer, primary_key=True)

    station_id = Column(Integer, ForeignKey('stations.id'), nullable=False)
    station = relation(Station)

    order = Column(Integer, nullable=False)
    arrival = Column(mysql.MSTime)
    departure = Column(mysql.MSTime)

    def __init__(self, station, order, arrival=None, departure=None):
        self.station = station
        self.order = order
        self.arrival = arrival
        self.departure = departure

    def __eq__(self, other):
        return (self.station == other.station) and (self.order == other.order) and \
            (self.arrival == other.arrival) and (self.departure == other.departure)

    def __repr__(self):
        return "<Stop('%s', '%s', '%s', '%s')>" % (self.station, self.order, self.arrival, self.departure)
